package com.hrt.log;

import com.btcode.log.ILog;
import com.hrt.datasender.web.operInfo.OperInfoService;
import org.apache.log4j.Logger;

/**
 * 实现日志和消息队列的结合，日志既写文件，也发消息，方便前端展示
 * 
 * @author gislin
 *
 *
 */
public class Log4MQ implements ILog {

    private Logger log;

    private int errorCount = 0;

    private int logCount = 0;

    public Log4MQ(Logger log) {
        this.log = log;
    }

    @Override
    public void info(Object message, Throwable throwable) {
        countInfo();
        log.info(message, throwable);
    }

    @Override
    public void error(Object message, Throwable throwable) {
        countError();
        log.error(message, throwable);
        OperInfoService.getInstance().error(message,throwable);
    }

    @Override
    public void debug(Object message, Throwable throwable) {
        countDebug();
        log.debug(message, throwable);
    }

    private void countError() {
        logCount++;
        errorCount++;
    }

    private void countInfo() {
        logCount++;
    }

    private void countDebug() {
        logCount++;
    }

    public int getErrorCount() {
        return errorCount;
    }

    public int getLogCount() {
        return logCount;
    }

    @Override
    public String getName() {
        return log.getName();
    }

    @Override
    public void info(Object message) {
        info(message, null);
    }

    @Override
    public void error(Object message) {
        error(message, null);
    }

    @Override
    public void debug(Object message) {
        debug(message, null);
    }

    @Override
    public void logOn() {

    }

    @Override
    public void logOff() {
        // TODO Auto-generated method stub

    }

}
